<form [formGroup]="objectForm" (ngSubmit)="save()" autocomplete="off">
    <div class="modal-header">
      <h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4>
      <button type="button" [disabled]="!closeEnabled" class="btn-close" aria-label="Close" (click)="cancel()">
      </button>
    </div>
    <div class="modal-body">
      <div class="row">
        <div class="col-md-8">
          <pngx-input-text i18n-title title="Name" formControlName="name" [error]="error?.name"></pngx-input-text>
        </div>
        <div class="col">
          <pngx-input-number i18n-title title="Sort order" formControlName="order" [showAdd]="false" [error]="error?.order"></pngx-input-number>
        </div>
      </div>
      <div class="row">
        <div class="col-md-4">
          <h5 class="border-bottom pb-2" i18n>Filters</h5>
          <p class="small" i18n>Process documents that match <em>all</em> filters specified below.</p>
          <pngx-input-select i18n-title title="Filter sources" [items]="sourceOptions" [multiple]="true" formControlName="sources" [error]="error?.filter_filename"></pngx-input-select>
          <pngx-input-text i18n-title title="Filter filename" formControlName="filter_filename" i18n-hint hint="Apply to documents that match this filename. Wildcards such as *.pdf or *invoice* are allowed. Case insensitive." [error]="error?.filter_filename"></pngx-input-text>
          <pngx-input-text i18n-title title="Filter path" formControlName="filter_path" i18n-hint hint="Apply to documents that match this path. Wildcards specified as * are allowed. Case insensitive.</a>" [error]="error?.filter_path"></pngx-input-text>
          <pngx-input-select i18n-title title="Filter mail rule" [items]="mailRules" [allowNull]="true" formControlName="filter_mailrule" i18n-hint hint="Apply to documents consumed via this mail rule." [error]="error?.filter_mailrule"></pngx-input-select>
        </div>
        <div class="col">
          <div class="row">
            <div class="col">
              <h5 class="border-bottom pb-2" i18n>Assignments</h5>
            </div>
          </div>
          <div class="row">
            <div class="col">
              <pngx-input-text i18n-title title="Assign title" formControlName="assign_title" i18n-hint hint="Can include some placeholders, see <a target='_blank' href='https://docs.paperless-ngx.com/usage/#consumption-templates'>documentation</a>." [error]="error?.assign_title"></pngx-input-text>
              <pngx-input-tags [allowCreate]="false" i18n-title title="Assign tags" formControlName="assign_tags"></pngx-input-tags>
              <pngx-input-select i18n-title title="Assign document type" [items]="documentTypes" [allowNull]="true" formControlName="assign_document_type"></pngx-input-select>
              <pngx-input-select i18n-title title="Assign correspondent" [items]="correspondents" [allowNull]="true" formControlName="assign_correspondent"></pngx-input-select>
              <pngx-input-select i18n-title title="Assign storage path" [items]="storagePaths" [allowNull]="true" formControlName="assign_storage_path"></pngx-input-select>
              <pngx-input-select i18n-title title="Assign custom fields" multiple="true" [items]="customFields" [allowNull]="true" formControlName="assign_custom_fields"></pngx-input-select>
          </div>
          <div class="col">
            <pngx-input-select i18n-title title="Assign owner" [items]="users" bindLabel="username" formControlName="assign_owner" [allowNull]="true"></pngx-input-select>
              <div>
                <label class="form-label" i18n>Assign view permissions</label>
                <div class="mb-2">
                  <div class="row mb-1">
                    <div class="col-lg-3">
                      <label class="form-label d-block my-2 text-nowrap" i18n>Users:</label>
                    </div>
                    <div class="col-lg-9">
                      <pngx-permissions-user type="view" formControlName="assign_view_users"></pngx-permissions-user>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-lg-3">
                      <label class="form-label d-block my-2 text-nowrap" i18n>Groups:</label>
                    </div>
                    <div class="col-lg-9">
                      <pngx-permissions-group type="view" formControlName="assign_view_groups"></pngx-permissions-group>
                    </div>
                  </div>
                </div>
                <label class="form-label" i18n>Assign edit permissions</label>
                <div>
                  <div class="row mb-1">
                    <div class="col-lg-3">
                      <label class="form-label d-block my-2 text-nowrap" i18n>Users:</label>
                    </div>
                    <div class="col-lg-9">
                      <pngx-permissions-user type="change" formControlName="assign_change_users"></pngx-permissions-user>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-lg-3">
                      <label class="form-label d-block my-2 text-nowrap" i18n>Groups:</label>
                    </div>
                    <div class="col-lg-9">
                      <pngx-permissions-group type="change" formControlName="assign_change_groups"></pngx-permissions-group>
                    </div>
                  </div>
                  <small class="form-text text-muted text-end d-block" i18n>Edit permissions also grant viewing permissions</small>
                </div>
              </div>
          </div>
        </div>
      </div>
      </div>
    </div>
    <div class="modal-footer">
      <span class="text-danger" *ngIf="error?.non_field_errors"><ng-container i18n>Error</ng-container>: {{error.non_field_errors}}</span>
      <button type="button" class="btn btn-outline-secondary" (click)="cancel()" i18n [disabled]="networkActive">Cancel</button>
      <button type="submit" class="btn btn-primary" i18n [disabled]="networkActive">Save</button>
    </div>
  </form>
